// 使用 页面中 需 引入 import { judgeMonCode, handleMonTextForNewsList } from '@/utils/formatMonTextStyle.js'

// 判断蒙文编码
// export function judgeMonCode(text) {
//   if (!text) return false
//   let mon = /^[\u180a-\u18af]/g

//   // 清除字符串中的 数字
//   text = text.replace(/[0-9]/g, ""); 
//   text = text.trim()

//   // 清除 《 
//   if (text.length > 2) {
//     text = text.substring(1)
//   }

//   // debugger
//   return mon.test(text) 
// }

// 中文 蒙文 全部纵向排列
export function judgeMonCode(text) {
  return true
}


// 时间 转 时间戳
export function formatDate(str_time) {
  if (str_time) {
    var date = new Date(str_time); 
    date = new Date(str_time.replace(/-/g, '/'));
    let time1 = date.getTime();
    return time1;
  } else {
    return false
  }
};

// 处理 新闻列表 蒙文 样式
export function handleMonTextForNewsList(time, text) {
  // eslint-disable-next-line no-lone-blocks, no-unused-expressions, no-undef
  if (formatDate(time)) {
    if (formatDate(time) > 1696089600000) {
      return (<span 
        className="mon_text1" 
        style={{
          // height: "80px", 
          maxHeight: "90px",
          padding: "0 5px", 
          writingMode: "vertical-lr", 
          textAlign: "left", 
          wordWrap: "initial",
          wordBreak: "initial",
          fontSize: "22px" 
        }}
      >
        {text}
      </span>)
    } else {
      return (<span 
        className="mon_text2" 
        style={{
          // height: "80px", 
          maxHeight: "90px",
          padding: "0 5px", 
          writingMode: "vertical-lr", 
          textAlign: "left", 
          wordWrap: "initial",
          wordBreak: "initial",
          fontSize: "22px" 
        }}
      >
        {text}
      </span>)
    }
  } else {
    return (<span 
      className="mon_text1" 
      style={{
        // height: "80px", 
        maxHeight: "90px",
        padding: "0 5px", 
        writingMode: "vertical-lr", 
        textAlign: "left", 
        wordWrap: "initial",
        wordBreak: "initial",
        fontSize: "22px" 
      }}
    >
      {text}
    </span>)
  }
}

// 处理 直播列表 蒙文样式 （判断 中文 或 蒙文）
export function handleMonTextForLiveList(time, item) {
  // eslint-disable-next-line no-lone-blocks, no-unused-expressions, no-undef
  if (formatDate(time) > 1696089600000) {
    return (
      <span 
        class="mon_text1"
        style={{ height: "180px", cursor: "pointer", writingMode: "vertical-lr", whiteSpace: "pre-wrap" }} 
        onClick={() => this.goDetail(item)} title={item.title}
      >
        {item.title}
      </span>
    )
  } else {
    return (
      <span 
        class="mon_text2"
        style={{ height: "180px", cursor: "pointer", writingMode: "vertical-lr", whiteSpace: "pre-wrap" }} 
        onClick={() => this.goDetail(item)} title={item.title}
      >
        {item.title}
      </span>
    )
  }
}

// 清除 文章详情 富文本 content 中的蒙文字体
export function formatContentFontFamily(content) {
  if (content) {
    content = content.replaceAll(
      /font-family: mongolian;|font-family: haWang;|font-family: sonin;|font-family: haraTegsi;|font-family: maoBi;|text-wrap: nowrap;/g,
      " "
    );
    // console.log('content : ', content);
    return content
  }
} 

// 清除 图片链接字符串 中 的 '\'
export function formatImgUrl(url) {
  if (url) {
    url = url.replace(/\|/g, '')
    return url;
  } 
};
